package com.medi.web.controller.business;

import com.medi.common.annotation.Log;
import com.medi.common.core.controller.BaseController;
import com.medi.common.core.domain.AjaxResult;
import com.medi.common.core.page.TableDataInfo;
import com.medi.common.enums.BusinessType;
import com.medi.system.domain.SysNotice;
import com.medi.system.service.ISysNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公告内容
 *
 * @author medi
 */
@Api(tags = "后台管理-公告内容")
@RestController
@RequestMapping("/business/news")
public class NewsController extends BaseController {

    @Autowired
    private ISysNoticeService noticeService;

    /**
     * 查询新闻列表
     */
    @ApiOperation("查询新闻列表")
    //@PreAuthorize("@ss.hasPermi('business:news:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysNotice notice) {
        startPage();
        List<SysNotice> list = noticeService.selectNoticeList(notice);
        return getDataTable(list);
    }

    /**
     * 查询新闻详情
     */
    @ApiOperation("查询新闻详情")
    //@PreAuthorize("@ss.hasPermi('business:news:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(noticeService.selectNoticeById(id));
    }

    /**
     * 删除新闻
     */
    @ApiOperation("删除新闻")
    //@PreAuthorize("@ss.hasPermi('business:news:remove')")
    @Log(title = "新闻", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return toAjax(noticeService.deleteNoticeById(id));
    }
}
